package code.utils
{
	import code.consts.DirectionConst;

	public class DirectionUtil
	{
		
		public function DirectionUtil()
		{
		}
		
		/**
		 *	传入角度是否为需要镜像翻转的角度 
		 * @param direction
		 * @return 
		 * 
		 */
		public static function isMirrorDirection(direction:int):Boolean
		{
			if(225<=direction && direction<360)
			{
				return true;
			}
			return false;
		}
		
		/**
		 *	传入方向字符串是否为需要镜像翻转的方向 
		 * @param direction
		 * @return 
		 * 
		 */
		public static function isMirrorDirectionStr(direction:String):Boolean
		{
			if(direction == DirectionConst.LEFT || direction == DirectionConst.LEFT_DOWN || direction == DirectionConst.LEFT_UP)
			{
				return true;
			}
			return false;
		}
		
		/**
		 *	镜像方向转化为原始方向字符串 
		 * @param mirrorStr
		 * @return 
		 * 
		 */
		public static function mirrorToOriginal(mirrorStr:String):String
		{
			if(mirrorStr.match("L") != null)
			{
				return mirrorStr.replace("L","R");
			}
			throw new Error("传入的必须是左侧镜像方向L或LU或LD");
			return null;
		}
		
		/**
		 *	原始方向转化为镜像方向字符串 
		 * @param mirrorStr
		 * @return 
		 * 
		 */
		public static function originalToMirror(mirrorStr:String):String
		{
			if(mirrorStr.match("R") != null)
			{
				return mirrorStr.replace("R","L");
			}
			throw new Error("传入的必须是左侧镜像方向L或LU或LD");
			return null;
		}
		
		/**
		 *	方向值（角度:0~360）转化为方向字符串( DirectionConst.UP , DirectionConst.RIGHT .....) 
		 * @param degree
		 * @return 
		 * 
		 */
		public static function directionToDirectionStr(direction:int):String
		{
			direction = direction%360;
			if(0<=direction&&direction<45)
			{
				return DirectionConst.UP;
			}
			else if(45<=direction&&direction<90)
			{
				return DirectionConst.RIGHT_UP;
			}
			else if(90<=direction&&direction<135)
			{
				return DirectionConst.RIGHT;
			}
			else if(135<=direction&&direction<180)
			{
				return DirectionConst.RIGHT_DOWN;
			}
			else if(180<=direction&&direction<225)
			{
				return DirectionConst.DOWN;
			}
			else if(225<=direction&&direction<270)
			{
				return DirectionConst.LEFT_DOWN;
			}
			else if(270<=direction&&direction<315)
			{
				return DirectionConst.LEFT;
			}
			else if(315<=direction&&direction<360)
			{
				return DirectionConst.LEFT_UP;
			}
			return DirectionConst.UP;	
		}
	}
}